package com.cs2340.practice;

import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class TaskListAdapter extends BaseAdapter {

	private ArrayList<String> listOTasks;
	private Context context;


	TaskListAdapter(ArrayList<String> taskList, Context myContext) {
		listOTasks = taskList;
		context = myContext;
	;
	}

	@Override
	public int getCount() {

		return listOTasks.size();
	}

	@Override
	public Object getItem(int position) {

		// TODO Auto-generated method stub
		return listOTasks.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return listOTasks.get(position).hashCode();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		View newView;
		TextView tv;

		final LayoutInflater li = (LayoutInflater) this.context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		if (convertView == null) {
			// if it's not recycled, initialize some attributes
			newView = li.inflate(R.layout.text, null);
			//newView.setClickable(true);

			/*
			 * incase we want to add and image or something iv = (ImageView)
			 * v.findViewById(R.id.icon_image);
			 * iv.setScaleType(ImageView.ScaleType.CENTER_CROP);
			 * iv.setPadding(8, 8, 8, 8);
			 */
			} else {
			newView = convertView;
		}
		tv = (TextView) newView;
		tv.setText(listOTasks.get(position).toString());

		// TODO Auto-generated method stub
		// create text view
		return tv;
	}

}
